Skip to content

Fix PyCall::PythonNotFound on Windows - #236

Merged
mrkn merged 11 commits into
red-data-tools:masterfrom
felixmarch:claude/pensive-clarke-twnev3
Nov 13, 2026
Merged

mrkn merged 11 commits into
red-data-tools:masterfrom
felixmarch:claude/pensive-clarke-twnev3

Conversation

@felixmarch

Copy link
Copy Markdown
Contributor

Fixes #86

Problem

On Windows, PyCall failed to find or load Python for three separate reasons:

  1. Python that isn't on PATH was never found, which is the usual case for Anaconda.
  2. sysconfig has no SHLIB_SUFFIX on Windows, so building the candidate names raised TypeError.
  3. Fiddle.dlopen of the correct python3xx.dll failed with "No such file or directory".

The third error is misleading. It looked like a forward slash vs. backslash problem, but it isn't: backslashes fail the same way, and forward slashes work once the dependencies resolve. The actual cause is that the DLL's dependencies, such as zlib.dll in the same folder, aren't found. Adding the folder to PATH doesn't help on RubyInstaller, which excludes PATH from the DLL search.

Changes

All code changes are in lib/pycall/libpython/finder.rb:

  • Finding Python: after python3 and python, try python.exe in CONDA_PREFIX, then the PEP 514 registry entries under Software\Python, including ContinuumAnalytics. Entries for another architecture are skipped. An explicitly given PYTHON is still used alone.
  • Library names: default SHLIB_SUFFIX to .dll and add the python311.dll-style name.
  • DLL search: register the DLL's folder and Library\bin with RubyInstaller::Runtime.add_dll_directory, or prepend them to PATH on other Ruby distributions.
  • Quieter startup: hide the "Python was not found" message from the Microsoft Store python.exe alias unless PYCALL_DEBUG_FIND_LIBPYTHON is set.
  • Ruby 2.4: use String#chomp instead of String#delete_suffix, which requires Ruby 2.5. The new specs reach this line.

The README also describes the new search order on Windows.

Testing

Tested on Windows Server 2025 with RubyInstaller 3.4 (UCRT) and Anaconda (Python 3.14):

  • rake spec: 220 examples, 0 failures, 27 pending
  • Works with PYTHON set, and with only CONDA_PREFIX set, including importing ssl, ctypes, sqlite3, numpy and pandas
  • Registry lookup found Anaconda end to end through a temporary HKCU key

The CI and Windows workflows pass on the fork.

Limitations

  • An Anaconda install with no registry entry, no CONDA_PREFIX and no PYTHON still raises PythonNotFound.
  • The real Software\Python key was not exercised end to end, because the test machine has no such entry. The lookup is covered by specs against a temporary key.
  • The PATH fallback for Rubies other than RubyInstaller is covered by specs only.

The registry specs create and delete a temporary key under HKCU when run on Windows.

🤖 Generated with Claude Code

felixmarch and others added 2 commits November 6, 2026 17:11
Python was not found or failed to load on Windows for three reasons:

- Python that is not on PATH was never found. Fall back to python.exe in
  CONDA_PREFIX, and then to the PEP 514 entries in the registry under
  Software\Python, which includes ContinuumAnalytics for Anaconda. An
  explicitly given python is still used alone.

- sysconfig has no SHLIB_SUFFIX on Windows, which raised TypeError while
  building the candidate names. Default it to .dll and add the
  python311-style name.

- Fiddle.dlopen of the right python3xx.dll failed with "No such file or
  directory". The slashes are not the cause: backslashes fail the same way
  and forward slashes work once the dependencies resolve. The cause is that
  dependencies like zlib.dll in the folder of the DLL are not found, and
  RubyInstaller excludes PATH from the DLL search. Register the folder of
  the DLL and Library\bin with RubyInstaller::Runtime.add_dll_directory, or
  prepend them to PATH on other Ruby distributions.

Also stop printing the complaint of the Microsoft Store python.exe alias on
every start, unless PYCALL_DEBUG_FIND_LIBPYTHON is set.

Fixes red-data-tools#86

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
String#delete_suffix requires Ruby 2.5, so candidate_names raised
NoMethodError on Ruby 2.4 when python_config has LIBRARY. It was not
noticed because candidate_names only runs when the first candidate fails
to load, until the new finder spec reached it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mrkn

mrkn commented Nov 6, 2026

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T01:45:03.254672Z baf150b Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 3eddea54ea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mrkn

mrkn commented Nov 6, 2026

Copy link
Copy Markdown
Member

@felixmarch Thank you for the patch! The Windows-specific logic is making the existing Finder methods harder to follow.

Before merging, could you move the Windows-specific implementation into a FinderForWindows module defined in a separate file, and delegate to it entirely at the beginning of Finder.find_libpython, as shown below?

return FinderForWindows.find_libpython(python) if windows?

This would keep the existing flow clear and the Windows implementation separate.

As requested in the review, Finder.find_libpython now delegates to
FinderForWindows.find_libpython at its beginning on Windows, and Finder
is back to its previous flow.

FinderForWindows keeps the Windows behavior as it was: finding Python in
CONDA_PREFIX and the registry, the .dll suffix and python311.dll-style
names, and registering the DLL folders before Fiddle.dlopen. It reuses
Finder.normalize_path, Finder.make_libpaths and the investigator script.

It now raises PythonNotFound when no library can be loaded, instead of
returning the result of the last candidate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@felixmarch

felixmarch commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Okay, Windows implementation is moved into FinderForWindows in lib/pycall/libpython/finder_for_windows.rb (3120ab7). Finder.find_libpython now starts with return FinderForWindows.find_libpython(python) if windows?, and the rest of Finder is the same as on master.

On Windows, find_libpython will raise PyCall::PythonNotFound when no candidate library can be loaded.

module LibPython
# Everything except the real registry access runs on all platforms, so that
# the Windows behavior is also covered by the CI on Linux and macOS.
::RSpec.describe FinderForWindows do

@mrkn mrkn Nov 11, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixmarch Could you please put the if: Fiddle::WINDOWS condition on this context instead of the context of Windows registry things?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 6d301f1: the if: Fiddle::WINDOWS condition is now on the top-level describe FinderForWindows, and I removed it from the registry specs.

@mrkn

mrkn commented Nov 11, 2026

Copy link
Copy Markdown
Member

@felixmarch Could you clarify which Python distributions and installation setups are actually tested by the Windows jobs in GitHub Actions?

I see jobs using actions/setup-python and Miniconda, with PYTHON=python set in both cases. Are configurations with PYTHON unset, Python outside PATH, or discovery through CONDA_PREFIX or the PEP 514 registry also tested with real Python installations?

I’d like to understand which cases are covered by end-to-end CI tests and which are covered only by unit tests or manual testing.

kou pushed a commit that referenced this pull request Nov 11, 2026
…238)

Fixes #87.

## Problem

`PyCall.import_module('scipy.stats').norm.pdf([1, 2, 3], 0, 10)` raises

```
TypeError: rv_continuous_frozen.pdf() takes 2 positional arguments but 4 were given
```

while the same expression works in Python.

`scipy.stats.norm` is not a class or a function but a callable
*instance* of `norm_gen`. Ruby cannot distinguish `stats.norm` from
`stats.norm()`, and `pycall_pyobject_wrapper_wrapper_method` calls every
callable attribute, so `stats.norm.pdf(x, 0, 10)` is evaluated as
`stats.norm().pdf(x, 0, 10)`: `pdf` of a frozen distribution (loc=0,
scale=1), which only takes `x`.

## Change

When an attribute is accessed **without arguments**, it is called only
if it is a *routine*. Otherwise the callable object is returned as is.
**Calls with arguments are unchanged.**

"Routine" follows Python's own definition in `inspect.isroutine()`,
implemented in C with type checks (no Python-level call per access):

- `builtin_function_or_method`, bound `method`, and `method-wrapper`
(and subtypes)
- non-data descriptors: types that define `__get__` but not `__set__`.
This covers Python functions, method descriptors, slot wrappers, Cython
functions (`cython_function_or_method`), `functools.lru_cache` wrappers,
numpy's `_ArrayFunctionDispatcher` (`np.sum`, etc.), and so on.

Two additions to keep existing code working:

- `functools.partial`: it is a routine on Python 3.14+ (it gained
`__get__`), and it is special-cased so that the behavior does not depend
on the Python version.
- Ruby `Proc`/`Method` objects stored in a Python attribute are still
called, as before.

Class objects are still returned as is, as before.

## Behavior change

With no arguments, these are now **returned** instead of being called:

| Attribute | Before | After |
|---|---|---|
| `scipy.stats.norm` and other rv instances | called: frozen
distribution | the generator object |
| numpy ufuncs (`np.sin`, `scipy.special.gamma`) | called with no args:
`TypeError` | the ufunc object |
| other instances of classes defining `__call__`,
`operator.itemgetter(...)` | called | the object |
| a non-callable Ruby object stored in a Python attribute | `TypeError:
non-callable ruby object` | the Ruby object |

Everything else is unchanged. I checked these against real numpy/scipy:
`np.get_include`, `np.random.random`, `np.random.default_rng` (Cython),
`ndarray.sum`/`copy`/`tolist`, staticmethods and classmethods are all
still called without arguments.

**Risk:** code that relies on `obj.callable_instance` calling it with
zero arguments now gets the object back. It can use
`obj.callable_instance.()` (or `.call`) instead. The README section "The
callable attribute of an object" now documents this.

## Tests

- New `spec/pycall/callable_attribute_spec.rb` with a scipy-like helper
module `spec/python/pycall/callable_attribute.py` (no scipy needed). It
covers the callable-instance case (no args, positional args, keyword
args, `.()`, class/instance attributes). It also checks that
zero-argument functions, bound methods, staticmethods, classmethods,
builtin methods and functions, method-wrappers, `lru_cache` wrappers,
`partial` objects, callable non-data descriptors, and Ruby lambdas are
still called.
- Without the C change, the 4 callable-instance specs fail. With it, the
full suite passes: 212 examples, 0 failures, 27 pending.
- Tested on Windows Server 2025, RubyInstaller Ruby 3.4 (UCRT), Anaconda
Python 3.14.6, numpy 2.x and scipy 1.18. To load Python there, I used a
local workaround for the Windows finder (the issue addressed by #236);
it is not part of this PR.

## Not included

- `pyfrom ..., import: :norm` (`lib/pycall/import.rb`) still defines a
method that calls any non-class callable, so the same issue remains
there.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@felixmarch

felixmarch commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

@felixmarch Could you clarify which Python distributions and installation setups are actually tested by the Windows jobs in GitHub Actions?

I see jobs using actions/setup-python and Miniconda, with PYTHON=python set in both cases. Are configurations with PYTHON unset, Python outside PATH, or discovery through CONDA_PREFIX or the PEP 514 registry also tested with real Python installations?

I’d like to understand which cases are covered by end-to-end CI tests and which are covered only by unit tests or manual testing.

@mrkn I did not change workflow files but tested it manually like this:

> gem install pandas
> irb
require 'pandas'  #(error observed here)

> powershell
> . C:\Ruby34\bin\ridk.ps1 enable; gem build pycall.gemspec --output $env:TEMP\pycall-1.5.6.gem; gem install --local $env:TEMP\pycall-1.5.6.gem --no-document
> $env:PYTHON='C:\ProgramData\anaconda3\python.exe'; irb
require 'pandas'  #(error no longer observed)
PyCall::VERSION
Pandas::Series.new([1, 2, 3]).sum  #(works fine)

My current python is from Anaconda3-2026.07-1-Windows-x86_64, which is python 3.14.6

This issue has existed for long time, so I believe it happens to any version of anaconda in Windows (see my early report two years ago on issue #86).

As requested in the review, put the `if: Fiddle::WINDOWS` condition on
the whole FinderForWindows spec instead of only on the registry specs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mrkn

mrkn commented Nov 11, 2026

Copy link
Copy Markdown
Member

@felixmarch Thank you for clarifying. I think the behavior introduced by this PR needs to be tested against actual Python installations in CI running on Windows, rather than relying only on mocked tests.

Could you also update the Windows GitHub Actions workflow to cover the new discovery paths with real Python installations? This would let us verify that Python discovery and DLL loading work together in the environments this PR is intended to support.

felixmarch and others added 2 commits November 12, 2026 08:12
As requested in the review, add a discovery job to the Windows workflow
that uses real Python installations instead of mocks. Each job hides
every python.exe on PATH and checks that PyCall loads the expected
Python, imports modules that need DLLs, and passes the test suites:

- registry-pythoncore: Python registered under PythonCore
- registry-anaconda: Miniconda installed with /RegisterPython=1, the
  only Python registered (under ContinuumAnalytics)
- conda-prefix: a conda environment given by CONDA_PREFIX

finder_spec.rb is skipped there because it runs python on PATH.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The registry jobs found the expected Python, but two specs failed
because numpy was not installed there. Install numpy in both of them.

The runner image registers every Python in its tool cache under
PythonCore, so the registry-pythoncore job now removes all of them
except the Python of setup-python, and expects exactly that one.

Miniconda installed with /RegisterPython=1 registers itself under
PythonCore, not under ContinuumAnalytics, so rename registry-anaconda
to registry-miniconda and correct the comment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mrkn

mrkn commented Nov 12, 2026

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: baf150b383

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mrkn

mrkn commented Nov 12, 2026

Copy link
Copy Markdown
Member

@kou Could you please review the window finder and the workflow changes?

@mrkn
mrkn requested a review from kou November 12, 2026 01:46
@felixmarch

Copy link
Copy Markdown
Contributor Author

@mrkn I added a discovery job to the Windows workflow in d5c2fa6 and baf150b. It tests real Python installations, and each job first removes every python.exe from PATH, so PyCall has to find Python by itself:

  • registry-pythoncore: the Python from actions/setup-python, found through Software\Python\PythonCore. The runner image registers every Python in its tool cache, so the job removes all the other registrations first and expects exactly this one.
  • registry-miniconda: the latest Miniconda installed with /RegisterPython=1, after removing the runner's own registrations.
  • conda-prefix: a conda environment given by CONDA_PREFIX, with packages from conda-forge only.

Each job does the following:

  • Checks that sys.prefix is the expected installation.
  • Imports ctypes, ssl, sqlite3 and numpy, which need DLLs next to python3XX.dll or in conda's Library\bin.
  • Runs the spec and test suites against that Python. finder_spec.rb is skipped there because it runs python from PATH.

All three pass: https://github.com/felixmarch/pycall.rb/actions/runs/43131380225

One gap may remain. The current Miniconda installer registers itself under PythonCore, so the Software\Python\ContinuumAnalytics lookup is still covered only by the mocked specs. Older installers did register there. I checked Miniconda3-4.5.12-Windows-x86_64.exe (56 MB, January 2019) without running it, and it contains the registry paths Software\Python\ContinuumAnalytics\Anaconda37-64\InstallPath and the values ExecutablePath, SysVersion and SysArchitecture. I could add a job that installs it, probably with /RegisterPython=0 so that only the ContinuumAnalytics entry is left, which the job would confirm.

Can you please provide opinion on Anaconda's terms? The Miniconda installer is BSD-licensed, and Anaconda's payment terms apply to using its package repositories. The job would only download the installer and install numpy with pip. Still, the terms don't say explicitly whether downloading an installer from repo.anaconda.com in CI is fine for an open-source project. The registry-miniconda job already downloads the latest installer from there on each run, so the same question applies to it. Do you want to add the ContinuumAnalytics job, or keep the CI as it is?

@kou kou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we can use repo.anaconda.com to download an installer.
Or we can use Miniforge instead of Minoconda.

Can we simplify specs? I think that most checks are covered by Windows CI jobs.

end

def debug?
@debug ||= (ENV['PYCALL_DEBUG_FIND_LIBPYTHON'] == '1')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This result isn't cached with non '1' value. How about removing @debug ||=?

If we want to cache it, we can use @debug_env ||= ENV['PYCALL_DEBUG_FIND_LIBPYTHON'] || ''; @debug_env == '1'.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed @debug ||= in ba6f707, so the environment variable is read each time.


def add_dll_directory(path)
debug_report("add_dll_directory(#{path.inspect})")
if defined?(RubyInstaller::Runtime) && RubyInstaller::Runtime.respond_to?(:add_dll_directory)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the RubyInstaller::Runtime.respond_to?(:add_dll_directory) check?

Suggested change
if defined?(RubyInstaller::Runtime) && RubyInstaller::Runtime.respond_to?(:add_dll_directory)
if defined?(RubyInstaller::Runtime)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in ba6f707. RubyInstaller::Runtime.add_dll_directory exists since RubyInstaller 2.4.1-1, the first RubyInstaller2 release, so the check is not needed.

# implementation like the py launcher does, then Anaconda.
PYTHON_REGISTRY_COMPANIES = [
-'PythonCore',
-'ContinuumAnalytics',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'ContinuumAnalytics' is for old Miniconda, right? Can we remove this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Old installers like Miniconda3-4.5.12 (January 2019) contain Software\Python\ContinuumAnalytics, while the current ones register under PythonCore. I removed it in ba6f707, so only PythonCore is preferred now. The entries of every company are still read, so an old installation registered under ContinuumAnalytics is still found, after PythonCore.

- Prefer only PythonCore in the registry.  ContinuumAnalytics was
  written by old Anaconda installers; such entries are still found,
  after PythonCore, like those of any other company.
- Call RubyInstaller::Runtime.add_dll_directory whenever
  RubyInstaller::Runtime is defined, which has it since RubyInstaller
  2.4.1-1.
- Read PYCALL_DEBUG_FIND_LIBPYTHON each time, since @debug ||= did not
  cache a false result anyway.
- Install Miniforge instead of Miniconda in the discovery jobs, so that
  they use neither Anaconda's installers nor its default channels.
- Keep only the specs for what the discovery jobs cannot cover: an
  explicitly given python, the order and the architecture of the
  registry entries, and loading without RubyInstaller.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@felixmarch

Copy link
Copy Markdown
Contributor Author

@kou I switched the discovery jobs to Miniforge in ba6f707: registry-miniforge installs Miniforge with /RegisterPython=1, and conda-prefix uses setup-miniconda with miniforge-version: latest. So they use neither Anaconda's installers nor its default channels.

I also simplified the specs. finder_for_windows_spec.rb now covers only what the discovery jobs cannot set up: an explicitly given python, the order and the architecture of the registry entries, and loading without RubyInstaller. I removed the delegation specs from finder_spec.rb too, because every Windows and non-Windows job runs that code.

All the Windows jobs pass, including the three discovery jobs: https://github.com/felixmarch/pycall.rb/actions/runs/43156807845

@kou

kou commented Nov 12, 2026

Copy link
Copy Markdown
Member

Thanks. Could you check comments from Claude Code?


Can we move registry-pythoncore and conda-prefix to the existing test and conda jobs? It will simplify the workflow.

  • test job: The runner image already registers Pythons in its tool cache under HKLM\SOFTWARE\Python\PythonCore (3.11-3.15). So we can test registry discovery by just hiding python.exe from PATH and unsetting PYTHON. We don't need to remove registrations if we don't check which one is used. (The newest one is found. For example, 3.15 is found in the python: 3.11 job and numpy isn't installed in it. So we should import only standard libraries here.)

        - name: Find Python in the registry
          shell: pwsh
          run: |
            $env:PATH = ($env:PATH -split ';' | Where-Object {
              $_ -and -not (Test-Path (Join-Path $_ python.exe)) -and -not (Test-Path (Join-Path $_ python3.exe))
            }) -join ';'
            if (Get-Command python, python3 -ErrorAction SilentlyContinue) { throw 'Python is still on PATH' }
            Remove-Item Env:PYTHON -ErrorAction SilentlyContinue
            @'
            require 'pycall'
            puts PyCall.sys.prefix
            %w[ctypes ssl sqlite3].each {|name| PyCall.import_module(name) }
            '@ | ruby -Ilib -Iext/pycall
            if ($LASTEXITCODE) { exit $LASTEXITCODE }
          env:
            PYCALL_DEBUG_FIND_LIBPYTHON: 1
  • conda job: CONDA_PREFIX is already set by setup-miniconda. We can add the same step but check sys.prefix against CONDA_PREFIX and import numpy too:

    require 'pycall'
    prefix = PyCall.sys.prefix
    abort "Unexpected Python: #{prefix}" unless File.identical?(prefix, ENV['CONDA_PREFIX'])
    %w[ctypes ssl sqlite3 numpy].each {|name| PyCall.import_module(name) }

We don't need to run the full test suite again in these steps because the previous rake step already runs it.

Could you also update the existing conda job?

  • Remove continue-on-error: true. The steps fail on master with no implicit conversion of nil into String because SHLIB_SUFFIX is None in conda's Python. They pass with this PR. So we should detect regressions.
  • Remove the "Add conda's DLL path" step. It uses $GITHUB_PATH not $env:GITHUB_PATH, so it doesn't work (C:\Miniconda\Library\bin isn't in PATH in subsequent steps). This PR adds the DLL directories by itself.
  • Use miniforge-version: latest like the conda-prefix job. It currently uses the defaults channel (pkgs/main).

felixmarch and others added 3 commits November 12, 2026 15:37
As suggested in the review, simplify the workflow:

- The test job now also finds Python in the registry after hiding
  every python.exe on PATH.  The runner image registers the Pythons
  of its tool cache under PythonCore, and the newest one is used, so
  only standard libraries are imported there.
- The conda job now also finds Python in CONDA_PREFIX, which
  setup-miniconda sets, the same way, and imports numpy too.
- The conda job no longer continues on error.  Its steps failed on
  master because SHLIB_SUFFIX is None in conda's Python, and pass now.
- Remove the "Add conda's DLL path" step.  It wrote to $GITHUB_PATH
  instead of $env:GITHUB_PATH, so it never changed PATH, and PyCall
  adds the DLL directories by itself now.
- The conda job installs Miniforge instead of using the defaults
  channel.
- Only Miniforge registered by its installer is left in its own job,
  which still runs the suites with the Python that PyCall finds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With Miniforge, bundle install failed to build fiddle because the
compiler of MSYS2 failed while the conda-forge environment came first
in PATH.  Build the gems and the extension before setup-miniconda, as
the former conda-prefix job did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rake runs extconf.rb again, because the Makefile depends on its
directory, which the build changes after writing the Makefile.  The
compiler then fails while the conda-forge environment is activated, so
run the test and spec suites directly, as the registry job does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@felixmarch

Copy link
Copy Markdown
Contributor Author

@kou I've done these in 6f6e159, 3099185 and cfd2e9f.

  • test job: added the "Find Python in the registry" step as you suggested. It imports only standard libraries; in the python: 3.11 job it found 3.15.2.
  • conda job: added "Find Python in CONDA_PREFIX", which checks sys.prefix against CONDA_PREFIX and imports numpy too. I removed continue-on-error: true and the "Add conda's DLL path" step, and the job now uses miniforge-version: latest with conda-remove-defaults: true.
  • With Miniforge, the compiler of MSYS2 fails while the conda-forge environment is activated, because it comes first in PATH. So the conda job now builds before setup-miniconda, and runs the suites with ruby test/run-test.rb and rspec instead of rake, which runs extconf.rb again.
  • The discovery job is now registry, with only Miniforge registered by its installer, because the other jobs don't cover that case. It still runs the spec and test suites, because no other job runs them with the Python that PyCall finds by itself. I can drop them if you prefer.

I also confirmed your points in the CI logs. On master, the conda job fails with no implicit conversion of nil into String at finder.rb:127. With this PR, it passes with 0 failures. C:\Miniconda\Library\bin was not in PATH.

All the Windows jobs pass: https://github.com/felixmarch/pycall.rb/actions/runs/43180929779

Glad to know we're using the same AI tool here. Yes, I'm using Claude Code for all the coding in this PR.

@kou kou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@mrkn
mrkn merged commit 9d6238d into red-data-tools:master Nov 13, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PyCall::PythonNotFound on Windows

3 participants